<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        车位使用添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/css/main.css" media="all">
    <style>
        .imgs{display: none;}
    </style>

</head>
<body>

<div class="x-body">
    <form class="layui-form layui-form-pane" action="" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <c:if test="${not empty typeId && not empty week }">
                        <input type="hidden" name="typeId" value="${typeId}">
                        <input type="hidden" name="week" value="${week}">
                        <input type="hidden" name="roleId" value="${roleId}">
                    </c:if>
                    <c:if test="${not empty scheduling}">
                        <input type="hidden" name="id" value="${scheduling.id}">
                    </c:if>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>选择人员
                        </label>
                        <div class="layui-input-block">
                            <select name="userId" id="userId">
                                <c:if test="${not empty users}">
                                    <c:forEach items="${users}" var="user">
                                        <option value="${user.id}" <c:if test="${scheduling.userId == user.id}">selected</c:if>>${user.name}</option>
                                    </c:forEach>
                                </c:if>
                                <c:if test="${empty users}">
                                    <option value="-1">--暂无人员--</option>
                                </c:if>
                            </select>
                        </div>
                    </div>

                    <c:if test="${empty typeId && empty week}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class='x-red'>*</span>工作日分配
                            </label>
                            <div class="layui-input-block">
                                <select name="week" id="week" disabled>
                                    <option value="1" <c:if test="${scheduling.week == 1}">selected</c:if>>星期一</option>
                                    <option value="2" <c:if test="${scheduling.week == 2}">selected</c:if>>星期二</option>
                                    <option value="3" <c:if test="${scheduling.week == 3}">selected</c:if>>星期三</option>
                                    <option value="4" <c:if test="${scheduling.week == 4}">selected</c:if>>星期四</option>
                                    <option value="5" <c:if test="${scheduling.week == 5}">selected</c:if>>星期五</option>
                                    <option value="6" <c:if test="${scheduling.week == 6}">selected</c:if>>星期六</option>
                                    <option value="7" <c:if test="${scheduling.week == 7}">selected</c:if>>星期日</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class='x-red'>*</span>工作日分配
                            </label>
                            <div class="layui-input-block">
                                <select name="typeId" id="typeId" disabled>
                                    <c:forEach items="${type}" var="schedulingType">
                                        <option value="${schedulingType.id}" <c:if test="${scheduling.typeId == schedulingType.id}">selected</c:if>>${schedulingType.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                    </c:if>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>开始时间
                        </label>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="time" name="startTime" class="layui-input" id="startTime" value="<c:if test="${not empty scheduling.startTime}">${scheduling.startTime}</c:if><c:if test="${empty scheduling.startTime}">${preEndTime}</c:if>"
                                       placeholder="开始时间">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>结束时间
                        </label>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="time" name="endTime" class="layui-input" id="endTime" value="${scheduling.endTime}"
                                       placeholder="结束时间">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>
                    <div style="height:100px;"></div>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="/lib/layui/layui.js" charset="utf-8"></script>
<script src="/js/x-layui.js" charset="utf-8"></script>

<script>
    layui.use(['laydate','element','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        laydate = layui.laydate;//日期插件
        form.render();
        //图片上传接口
        /*layui.upload({
          url: './upload.json' //上传接口
          ,success: function(res){ //上传成功后的回调
              console.log(res);
            $('#LAY_demo_upload').attr('src',res.url);
          }
        });*/
        //监听提交
        form.on('submit(add)', function(data){
            var user=$("input[name='user']").val();
            var week=$("input[name='week']").val();
            var type=$("input[name='type']").val();
            var start_time=$("input[name='startTime']").val();
            var end_time=$("input[name='endTime']").val();

            if(user==""){
                layer.msg('请选择用户',{icon:5,time:2000});return false;
            }
            if(week==""){
                layer.msg('请分配工作日',{icon:5,time:2000});return false;
            }
            if(type==""){
                layer.msg('请选择班次',{icon:5,time:2000});return false;
            }
            if(start_time==""){
                layer.msg('请选择开始时间',{icon:5,time:2000});return false;
            }
            if(end_time==""){
                layer.msg('请选择结束时间',{icon:5,time:2000});return false;
            }

            var date = new Date();
            var a = (""+start_time).split(":");
            var b = "${preEndTime}".split(":");

            if (date.setHours(a[0],a[1]) < date.setHours(b[0],b[1])){
                var res = layer.confirm("确认安排时间早于上一班结束时间？");
                return res;
            }
            var data=data.field;
            $.ajax({
                type:"post",
                url:"${url}",
                data:data,
                dataType:"json",
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.info, {icon: 6,time:2000},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;
                    }
                    else{
                        layer.msg(data.info,{icon:5,time:2000});return false;
                    }
                }
            });
        });
    })
</script>
</body>
</html>